#include<iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		int count = 0;
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				for (int k = 0; k <= n; k++) {
					if (n == i + j + k && i + j * 2 + k * 5 == m) {
						count++;
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}